package com.example.mybatisplus.web.controller;

import com.example.mybatisplus.model.domain.Reportup;
import com.example.mybatisplus.model.dto.DeleteDTO;
import com.example.mybatisplus.model.dto.PageDTO;
import com.example.mybatisplus.service.ReportupService;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.stereotype.Controller;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.example.mybatisplus.common.JsonResponse;
import com.example.mybatisplus.service.ReportService;
import com.example.mybatisplus.model.domain.Report;

import javax.servlet.http.HttpServletResponse;
import java.util.List;


/**
 *
 *  前端控制器
 *
 *
 * @author lxp
 * @since 2022-12-28
 * @version v1.0
 */
@Controller
@RequestMapping("/api/report")
public class ReportController {

    private final Logger logger = LoggerFactory.getLogger( ReportController.class );

    @Autowired
    private ReportService reportService;

    @Autowired
    private ReportupService reportupService;

//    上传，路径新增到reportup里面
    @PostMapping("save")
    @ResponseBody
    public JsonResponse save(@RequestBody Report report){
        reportService.rep(report);
        reportService.insert(report);
        return JsonResponse.success(true);
    }

    @PostMapping("rep")
    @ResponseBody
    public JsonResponse rep(@RequestBody Report  report){
        //report    拿到upTitle   upDate  upContent
        reportService.rep(report);
        return JsonResponse.success(true);
    }


    @GetMapping("list")
    @ResponseBody
    public JsonResponse list(Report report, PageDTO pageDTO){
        return JsonResponse.success(reportService.listPage(report,pageDTO));
    }

    // 我的上报
    @PostMapping("apply")
    @ResponseBody
    public JsonResponse apply(){
        List<Report> apply = reportService.apply();
        return JsonResponse.success(apply);
    }


    @PostMapping("audit")
    @ResponseBody
    public JsonResponse audit(@RequestBody Report report){
        reportService.audit(report);
        return JsonResponse.success(true);
    }

    @PostMapping("removeByIds")
    @ResponseBody
    public JsonResponse removeByIds(@RequestBody DeleteDTO deleteDTO){
        boolean b = reportService.removeByIds(deleteDTO.getIds());
        return JsonResponse.success(b);
    }

}

